package viper.badRelays;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.KeyStroke;

/**
 * @author Kevin Sin
 * 
 * Revision number: 1
 * Date created: 1/17/10
 * Date of Last Back-up on SVN: none
 * 
 * <p>JPanel for when the user is logged out.  Code generated by NetBeans.
 */
public class BadRelaysLoggedOutPanel extends javax.swing.JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** Creates new form ViperJPanel */
	public BadRelaysLoggedOutPanel() {
		initComponents();
	}

	private javax.swing.JButton jButton1; //Directions
	private javax.swing.JTextField jTextField1; //text field to enter username
	private BufferedImage image;


	/** 
	 * This method is called from within the constructor to
	 * initialize the form.
	 */
	private void initComponents() {
		
		try {                
			image = ImageIO.read(new File("images/viper.gif"));
		} catch (IOException ex) {
			ex.printStackTrace();
		}

		new javax.swing.JLabel(); 
		jTextField1 = new javax.swing.JTextField(20);
		
		//pressing enter = clicking login
		Action enterPressed = new AbstractAction(){
			private static final long serialVersionUID = 1L;
			@Override
			public void actionPerformed(ActionEvent arg0) {
				jButton1ActionPerformed(arg0);
			}
		};
		jTextField1.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enterPressed");
		jTextField1.getActionMap().put("enterPressed", enterPressed);
		
		jButton1 = new javax.swing.JButton(); 
		jButton1.setText("OK");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});
		
		JPanel titlePane = new JPanel();
		titlePane.setBackground(Color.WHITE);
		JLabel label = new JLabel("VIPER - Relay Program");
		titlePane.setLayout(new BorderLayout());
		label.setHorizontalAlignment(JLabel.CENTER);
		label.setHorizontalTextPosition(JLabel.CENTER);
	    label.setFont(new Font("Courier New", Font.BOLD, 30));
        titlePane.setLayout(new BoxLayout(titlePane, BoxLayout.LINE_AXIS));
	    titlePane.add(label, BorderLayout.CENTER);
		
		JPanel buttonPane = new JPanel();
		buttonPane.setBackground(new Color(255, 255, 255));
        buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
        buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 50, 50, 50));
        buttonPane.add(Box.createHorizontalGlue());
        buttonPane.add(jTextField1);
        buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
        buttonPane.add(jButton1);

        setLayout(new BorderLayout());
        add(label, BorderLayout.NORTH);
        add(buttonPane, BorderLayout.SOUTH);
	}

	/**
	 * @param evt
	 * When OK button is pressed, log in.
	 */
	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
		String name = jTextField1.getText();
		BadRelaysStateManager.INSTANCE.login(name);
	}

	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.drawImage(image, 50, 60, null);
	}
	
}

